package com.medvalley.tcm.controller.admin.controller;

import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.controller.BaseController;
import com.medvalley.tcm.controller.admin.service.AppUserService;
import com.medvalley.tcm.controller.admin.vo.inputvo.SearchUserInputVo;
import com.medvalley.tcm.controller.admin.vo.outputvo.AppUserInfoOutputVo;
import com.medvalley.tcm.controller.admin.vo.outputvo.PageDataOutputVo;
import com.medvalley.tcm.controller.admin.vo.outputvo.ReportOutputVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author linsong
 * @date 2019/6/19 10:44
 **/
@RestController("adminAppUserController")
@RequestMapping("/admin")
@Api("app用户接口")
public class UserController extends BaseController {

    @Autowired
    private AppUserService appUserService;

    @RequestMapping(value = "/app_user/search", method = RequestMethod.POST)
    @ApiOperation("检索app用户")
    public Result pageAppUser(@ModelAttribute SearchUserInputVo searchUserInputVo) {
        PageDataOutputVo<AppUserInfoOutputVo> pageDataOutputVo = appUserService.pageAppUser(searchUserInputVo);
        return success(pageDataOutputVo);
    }

    @RequestMapping(value = "/app_user/delete", method = RequestMethod.POST)
    @ApiOperation("删除用户")
    public Result deleteUser(@RequestParam("id") long id) {
        appUserService.deleteUser(id);
        return success();
    }

    @RequestMapping(value = "/app_user/report", method = RequestMethod.POST)
    @ApiOperation("根据id查询关联报告")
    public Result searchJoinReport(@RequestParam("userId") long userId) {
        List<ReportOutputVo> reportOutputVoList = appUserService.findReportById(userId);
        return success(reportOutputVoList);
    }

    //    @RequestMapping(value = "/app_user/report_2", method = RequestMethod.POST)
//    @ApiOperation("根据手机号查询关联报告")
//    public Result searchJoinReport(@RequestParam("phone") String phone) {
//        List<ReportOutputVo> reportOutputVoList = appUserService.findReportByPhone(phone)
//        return success(reportOutputVoList);
//    }
    @RequestMapping(value = "/app_user/delete/sick_user", method = RequestMethod.POST)
    @ApiOperation("删除某条关联报告")
    public Result deleteSickAndUser(@RequestParam("sickAndUserId") long sickAndUserId) {
        appUserService.deleteSickAndUser(sickAndUserId);
        return success();
    }

    @RequestMapping(value = "/app_user/clear_user_info", method = RequestMethod.POST)
    @ApiOperation("清楚用户信息")
    public Result clearUserInfo(@RequestParam("userId") long userId) {
        appUserService.clearUserInfo(userId);
        return success();
    }


}
